USE [cloudmusicdc]
GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID('PlaylistAddPlaylistData'))
BEGIN
    DROP PROCEDURE PlaylistAddPlaylistData
END

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/****** Object:  StoredProcedure [dbo].[PlaylistAddPlaylistData]    Script Date: 12/05/2013 23:57:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Tien>
-- Create date: <5/12/2013>
-- Description:	<>
-- =============================================
CREATE PROCEDURE [dbo].[PlaylistAddPlaylistData]
	@Id INT output,
	@Name NVARCHAR(MAX),
	@DateCreated DATETIME,
	@LastPlayed DATETIME,
	@UserId INT
AS
DECLARE
	@intReturn      INT,
	@uId			INT
BEGIN
	SET NOCOUNT ON;
	
	SET @uId = NULL
	SELECT TOP 1
		@uId = @UserId
	FROM dbo.[User]
	WHERE Id = @UserId
	
	IF @uId IS NOT NULL BEGIN
		INSERT INTO Playlist(Name, DateCreated, LastPlayed, UserId)
		VALUES(@Name, @DateCreated, @LastPlayed, @UserId)
	END
	ELSE BEGIN
		SET @intReturn = 0
	END
	SET @Id = (SELECT SCOPE_IDENTITY())
END
